package org.setamv.springcloud.entity;

import com.fasterxml.jackson.annotation.JsonFormat;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import java.io.Serializable;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 用户实体类
 */
@XmlRootElement
public class User implements Serializable {

    private static final long serialVersionUID = 1L;

    @XmlElement
    private String id;

    @XmlElement
    private String name;

    @XmlElement
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date birthDate;

    public User() {}
    public User(String id, String name, String birthDate) {
        this.id = id;
        this.name = name;
        if (birthDate != null && !"".equals(birthDate.trim())) {
            DateFormat dfm = new SimpleDateFormat("yyyy-MM-dd");
            try {
                this.birthDate = dfm.parse(birthDate);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Date getBirthDate() {
        return birthDate;
    }

    public void setBirthDate(Date birthDate) {
        this.birthDate = birthDate;
    }
}
